/**
 * 发布页面相关接口
 */
import request from "@/utils/request";
import env from "@/utils/env";
import { getItem, setItem } from "@/utils/localStorage";

// 线上发布
export const onlineIssue = (data) => {
  return request({
    method: "POST",
    url: "/studio/user/online",
    data,
  });
};

export const uploadImage = async (urlList) => {
  console.log("for循环外面urlList：", urlList);
  for (let i = 0; i < urlList.length; i++) {
    await uni.uploadFile({
      // url: `${env.baseUrl}/result/upload`,
      url: `${env.baseUrl}/studio/result/upload/${getItem("userInfo").id}`,
      fileType: "video",
      filePath: String(urlList[i]),
      name: "files",
      formData: {
        // id: getItem("userInfo").id,
        id: 13,
      },
      success(res) {
        console.log(`上传视频：${i}`, res);
      },
    });
  }
};

// 上传图片
// export const uploadImage = (data, url) => {
//   let toBase64Url;
//   uni.request({
//     url: "/user/online",
//     method: "POST",
//     responseType: "arraybuffer",
//     success: async (res) => {
//       let base64 = wx.arrayBufferToBase64(res.data); //把arraybuffer转成base64
//       toBase64Url = "data:image/jpeg;base64," + base64;
//       //将base64数据传到后台方法中
//       console.log("base64:", base64);

//       getImgByKey(toBase64Url).then((res) => {
//         if (res.data.imgUrl) {
//           uni.showToast({
//             title: "上传成功！",
//             icon: "success",
//           });
//         }
//       });
//     },
//   });
// };

// 线下面谈
export const offlineIssue = (data) => {
  return request({
    method: "POST",
    url: "/studio/user/offline",
    data,
  });
};

// 获取简历提交状态
export const issueStatus = () => {
  return request({
    method: "GET",
    // url: `/front/user/status?id=${getItem("userInfo").id}`,
    url: `/studio/resume/${getItem("userInfo").id}`,
  });
};
